package com.foreknow.controller;

import com.foreknow.po.Orders;
import com.foreknow.service.Impl.OrdersServiceImpl;
import com.foreknow.service.OrdersService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class OrdersController {

    public Object createOrders(HttpServletRequest request){
        OrdersService service = new OrdersServiceImpl();
        String userId = request.getParameter("userId");
        Integer businessId = Integer.parseInt(request.getParameter("businessId"));
        Integer daId = Integer.parseInt(request.getParameter("daId"));
        Double orderTotal =Double.parseDouble(request.getParameter("orderTotal"));
        Integer result = service.createOrders(userId,businessId,daId,orderTotal);
        return result;
    }

    public Object getOrdersById(HttpServletRequest request){
        OrdersService service = new OrdersServiceImpl();
        Integer orderId = Integer.parseInt(request.getParameter("orderId"));
        Orders orders = service.getOrdersById(orderId);
        return orders;
    }

    public Object listOrdersByUserId(HttpServletRequest request){
        OrdersService service = new OrdersServiceImpl();
        String userId = request.getParameter("userId");
        List<Orders> list = service.listOrdersByUserId(userId);
        return list;
    }


}
